function calcNights(checkInDate, checkOutDate) {
    // 获取两个日期对象的时间戳
    let time1 = new Date(checkInDate).getTime();
    let time2 = new Date(checkOutDate).getTime();

    // 计算相差的毫秒数，并将其转换为天数
    return Math.floor((time2 - time1) / (1000 * 60 * 60 * 24));
}

function timestampToDateFormat(timestamp) {
    const dateObj = new Date(timestamp); // 创建Date对象
    const year = dateObj.getFullYear(); // 获取年份
    const month = ("0" + (dateObj.getMonth() + 1)).slice(-2); // 获取月份，并补零
    const day = ("0" + dateObj.getDate()).slice(-2); // 获取日期，并补零

    return `${year}-${month}-${day}`; // 返回转换后的日期格式
}

function getSomeDate(addDays = 0) {
    const someDate = new Date();
    someDate.setDate(someDate.getDate() + addDays);
    const year = someDate.getFullYear();
    const month = String(someDate.getMonth() + 1).padStart(2, '0');
    const day = String(someDate.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
}


export {
    calcNights,
    timestampToDateFormat,
    getSomeDate
}
